package oakclub.entity;

import java.util.HashMap;
import java.util.Map;

public class EthnicityEntity extends BaseEntity
{
    private int id;

    public enum Ethnicity
    {
        UNKNOWN(0, "-"), EUROPEAN(1, "European"), AFRICAN(2, "African"), MIDDLE_EASTERN(3, "Middle Eastern"),
        INDIAN(4, "Indian"), LATINO_AMERICAN(5, "Latino American"), MIXED(6, "Mixed"),
        ASIAN(7, "Asian"), WHITE_CAUCASIAN(8, "White/Caucasian"), PACIFIC_ISLANDER(9, "Pacific Islander");

        private final int id;
        private final String name;

        private Ethnicity(int id, String name)
        {
            this.id = id;
            this.name = name;
        }

        public int getId()
        {
            return this.id;
        }

        public String getName()
        {
            return this.name;
        }

        private static final Map<Integer, Ethnicity> idLookup = new HashMap<>();
        private static final Map<String, Ethnicity> nameLookup = new HashMap<>();

        static
        {
            for(Ethnicity ethnicity : Ethnicity.values())
            {
                idLookup.put(ethnicity.id, ethnicity);
                nameLookup.put(ethnicity.name, ethnicity);
            }
        }

        public static String getName(int id)
        {
            Ethnicity ethnicity = idLookup.get(id);
            if(ethnicity == null)
            {
                return UNKNOWN.getName();
            }

            return ethnicity.getName();
        }

        public static int getId(String name)
        {
            if(name == null || name.isEmpty())
            {
                return UNKNOWN.getId();
            }

            Ethnicity ethnicity = nameLookup.get(name);
            if(ethnicity == null)
            {
                return UNKNOWN.getId();
            }

            return ethnicity.getId();
        }
    }

    public EthnicityEntity()
    {

    }

    public EthnicityEntity(int id)
    {
        this.id = id;
    }

    public EthnicityEntity(String name)
    {
        this.id = Ethnicity.getId(name);
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public String getName()
    {
        return Ethnicity.getName(this.id);
    }
}
